package com.hy.admin.helper;

import com.hy.admin.entity.PayOrderEntity;
import com.hy.admin.enums.EnumPayOrderStatus;
import com.hy.admin.enums.EnumPayResultStatus;
import com.hy.admin.helper.request.TradeRequest;

import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by wayne on 18/4/22.
 */
public class ResultUtil {
    public static Map result(EnumPayResultStatus enumResultStatus,PayOrderEntity payOrderEntity,String preAppPay) {
        if (enumResultStatus == null) {
            if (payOrderEntity.ispaying()) {
                enumResultStatus = EnumPayResultStatus.RETURN201;
            } else if (payOrderEntity.getStatus() == EnumPayOrderStatus.PAY_FAIL.getId()) {
                enumResultStatus = EnumPayResultStatus.RETURN203;
            } else {
                enumResultStatus = EnumPayResultStatus.RETURN202;
            }
        }
        Map map = new HashMap();
        map.put("code", enumResultStatus.getCode());
        map.put("resultMsg", payOrderEntity.getMessage());
        if (preAppPay != null) {
            map.put("payData", preAppPay);
        }
        map.put("outOrderNo", payOrderEntity.getOutOrderNo());
        map.put("orderNo", payOrderEntity.getOrderNo());
        return map;
    }

    public static Map result(TradeRequest tradeRequest) {
        Map map = new HashMap();
        map.put("code", EnumPayResultStatus.RETURN404.getCode());
        map.put("resultMsg", EnumPayResultStatus.RETURN404.getValue());
        map.put("outOrderNo", tradeRequest.getOutOrderNo());
        return map;
    }


    public static String replaceBlank(String str) {
        String dest = "";
        if (str!=null) {
            Pattern pattern = Pattern.compile("\\s*|\t|\r|\n");
            Matcher m = pattern.matcher(str);
            dest = m.replaceAll("");
        }
        return dest;
    }



}
